home *** CD-ROM | disk | FTP | other *** search
/ STraTOS 1997 April & May / STraTOS 1 - 1997 April & May.iso / CD01 / INTERNET / SITES / LITTLE / BMSRC.ZIP / LIGHTING.S < prev    next >
Encoding:
Text File  |  1996-11-23  |  6.0 KB  |  268 lines

  1. *=======================================================*
  2. *    Lighting module: latest update 25/03/96        *
  3. *=======================================================*
  4. *    Covers palette, colour & lighting processes    *
  5. *=======================================================*
  6. *    The contents of this module are temporary,    *
  7. *    and should not be taken seriously. I just     *
  8. *    wanted to see what lighting would look like!    *
  9. *=======================================================*
  10.  
  11. *-------------------------------------------------------*
  12. *    Dodgey hacks to set up sector lighting        *
  13. *-------------------------------------------------------*
  14.     txtlong
  15. *-------------------------------------------------------*
  16. set_lighting:
  17.     move.w        frame,framelock
  18.     rts
  19.  
  20. *-------------------------------------------------------*
  21.     txtlong
  22. *-------------------------------------------------------*
  23. process_lighting:
  24. *-------------------------------------------------------*
  25.     pushall
  26.     move.l        display_sectorptr(a6),a0
  27.     move.w        sector_special(a0),d2
  28.     move.w        sector_light(a0),d1
  29.     cmp.w        #1,d2
  30.     beq        .off
  31.     cmp.w        #2,d2
  32.     beq        .rand
  33.     cmp.w        #3,d2
  34.     beq        .rand
  35.     cmp.w        #4,d2
  36.     beq        .rand
  37.     cmp.w        #8,d2
  38.     beq        .osc
  39.     cmp.w        #12,d2
  40.     beq        .sync
  41.     cmp.w        #13,d2
  42.     beq        .sync
  43.     cmp.w        #17,d2
  44.     beq        .rand
  45. .end:    tst.w        d1
  46.     bpl.s        .p1
  47.     moveq        #0,d1
  48. .p1:    cmp.w        #255,d1
  49.     bmi.s        .ok
  50.     move.w        #255,d1
  51. .ok:    move.w        d1,sector_tag(a0)
  52.     move.w        d1,brightness
  53.     move.w        d1,d2
  54.     move.w        d1,d3
  55.  
  56.     move.w        sky_index,d5
  57.     cmp.w        display_ct(a6),d5
  58.     bne.s        .no_upper_sky
  59.     move.w        #upper_sky_lum,d2
  60. .no_upper_sky:
  61.     cmp.w        display_ft(a6),d5
  62.     bne.s        .no_lower_sky
  63.     move.w        #lower_sky_lum,d3
  64. .no_lower_sky:
  65.  
  66.     dspwrite.b    #setluminance_command
  67.     dspwrite.w    d1
  68.     dspwrite.w    d2
  69.     dspwrite.w    d3
  70.     popall
  71.     rts
  72.  
  73. .sync:
  74. .off:
  75.     move.w        framelock,d2
  76.     lsr.w        #4,d2
  77.     and.w        #8-1,d2
  78.     bne        .end
  79.     sub.w        #100,d1
  80.     bra        .end
  81.  
  82. .rand:    move.w        framelock,d0
  83.     and.w        #3,d0
  84.     bne.s        .off
  85. .osc:    move.w        d1,d0
  86.     lsr.w        #2,d0
  87.     sub.w        d0,d1
  88.     lea        sine,a1
  89.     move.w        framelock,d0
  90.     lsl.w        #6,d0
  91.     and.w        #sinres-1,d0
  92.     move.w        (a1,d0.w*2),d0
  93.     asr.w        #8,d0
  94.     add.w        d0,d1
  95.     bra        .end
  96.  
  97. *-------------------------------------------------------*
  98. *    Load palette from WAD and generate coltables    *
  99. *-------------------------------------------------------*
  100. init_colours:
  101. *-------------------------------------------------------*
  102.     lea        ascii_playpal,a0
  103.     bsr        load_resource
  104.     tst.l        d0
  105.     beq        err_missing
  106.     move.l        a6,playpal_ptr
  107.     lea        ascii_colormap,a0
  108.     bsr        load_resource
  109.     tst.l        d0
  110.     beq        err_missing
  111.     move.l        a6,colormap_ptr
  112.     move.w        #255,redfilter
  113.     move.w        #255,greenfilter
  114.     move.w        #255,bluefilter
  115.     lea        colourtables,a2
  116.     bsr        create_palettes
  117.     bsr        find_keycol
  118.     bsr        create_quick_alpha
  119.     rts
  120.  
  121. *-------------------------------------------------------*
  122. find_keycol:
  123. *-------------------------------------------------------*
  124.     move.l        playpal_ptr,a0
  125.     addq.l        #3,a0
  126.     moveq        #0,d5
  127.     moveq        #0,d6
  128.     move.l        #$3FFFFFFF,d4
  129.     move.w        #256-1-1,d7
  130. .loop:    moveq        #0,d1
  131.     move.b        (a0)+,d1
  132.     moveq        #0,d2
  133.     move.b        (a0)+,d2
  134.     moveq        #0,d3
  135.     move.b        (a0)+,d3
  136.     mulu.w        d1,d1
  137.     mulu.w        d2,d2
  138.     mulu.w        d3,d3
  139.     add.l        d1,d2
  140.     add.l        d2,d3
  141.     cmp.l        d4,d3
  142.     bgt.s        .no
  143.     move.l        d3,d4
  144.     move.l        d5,d6
  145. .no:    addq.l        #1,d5
  146.     dbra        d7,.loop
  147.     move.w        d6,black
  148.     rts
  149.  
  150. *-------------------------------------------------------*
  151. *    Generate 64 light levels of palette data    *
  152. *-------------------------------------------------------*
  153. create_palettes:
  154. *-------------------------------------------------------*
  155.     move.w        max_saturation,d0
  156.     sub.w        saturation,d0
  157.     add.l        #512*64,a2
  158.     move.w        #256,d5
  159.     moveq        #64-1,d7
  160. .loop:    move.w        #256-1,d6
  161.     move.l        playpal_ptr,a1
  162.     lea        -512(a2),a2
  163.     move.l        a2,a3
  164. .cols:    moveq        #0,d1
  165.     move.b        (a1)+,d1
  166.     moveq        #0,d2
  167.     move.b        (a1)+,d2
  168.     moveq        #0,d3
  169.     move.b        (a1)+,d3
  170.     mulu.w        redfilter,d1
  171.     mulu.w        greenfilter,d2
  172.     mulu.w        bluefilter,d3
  173.     lsr.l        #8,d1
  174.     lsr.l        #8,d2
  175.     lsr.l        #8,d3
  176.     mulu.w        saturation,d1
  177.     mulu.w        saturation,d2
  178.     mulu.w        saturation,d3
  179.     move.w        d0,d4
  180.     mulu.w        #base_red,d4
  181.     add.w        d4,d1
  182.     mulu.w        d5,d1
  183.     divu.w        max_saturation,d1        
  184.     move.w        d0,d4
  185.     mulu.w        #base_green,d4
  186.     add.w        d4,d2
  187.     mulu.w        d5,d2
  188.     divu.w        max_saturation,d2
  189.     move.w        d0,d4
  190.     mulu.w        #base_blue,d4
  191.     add.w        d4,d3
  192.     mulu.w        d5,d3
  193.     divu.w        max_saturation,d3
  194.     add.w        #127,d1
  195.     add.w        #127,d2
  196.     add.w        #127,d3
  197.     bfins        d1,d4{16:16}
  198.     bfins        d2,d4{21:16}
  199.     bfins        d3,d4{27:16}
  200.     ifd        intel
  201.     ror.w        #8,d4
  202.     endc
  203.     move.w        d4,(a3)+
  204.     dbra        d6,.cols
  205.     subq.w        #(256/64),d5
  206.     dbra        d7,.loop
  207.     rts
  208.  
  209. *-------------------------------------------------------*
  210. *    Generate quick-alpha table            *
  211. *-------------------------------------------------------*
  212. create_quick_alpha:
  213. *-------------------------------------------------------*
  214.     lea        quick_alpha_table,a5
  215.     move.l        #65536-1,d7
  216. .loop:    move.w        d7,d0
  217.     ifd        intel
  218.     ror.w        #8,d0
  219.     endc
  220.     bfextu        d0{16:08},d1
  221.     bfextu        d0{21:08},d2
  222.     bfextu        d0{27:08},d3
  223.     and.w        #%11111000,d1
  224.     and.w        #%11111100,d2
  225.     and.w        #%11111000,d3
  226.     mulu.w        #7,d1
  227.     mulu.w        #7,d2
  228.     mulu.w        #7,d3
  229.     add.w        #256,d1
  230.     add.w        #256,d2
  231.     add.w        #256,d3
  232.     lsr.w        #3,d1
  233.     lsr.w        #3,d2
  234.     lsr.w        #3,d3
  235.     bfins        d1,d0{16:08}
  236.     bfins        d2,d0{21:08}
  237.     bfins        d3,d0{27:08}
  238.     ifd        intel
  239.     ror.w        #8,d0
  240.     endc
  241.     move.w        d0,(a5,d7.l*2)
  242.     dbra        d7,.loop
  243.     rts
  244.  
  245. *-------------------------------------------------------*
  246.             datlong
  247. *-------------------------------------------------------*
  248.  
  249. max_saturation:        dc.w    256            ; maximum saturation range
  250. saturation:        dc.w    256            ; actual colour saturation level
  251.  
  252. *-------------------------------------------------------*
  253.             bsslong
  254. *-------------------------------------------------------*
  255.  
  256. redfilter:        ds.w    1            ; red filter 0-255
  257. greenfilter:        ds.w    1            ; green filter 0-255
  258. bluefilter:        ds.w    1            ; blue filter 0-255
  259. black:            ds.w    1
  260.  
  261. frame:            ds.w    1            ; some timing variables
  262. framelock:        ds.w    1            ; for hacked lighting effects
  263. brightness:        ds.w    1
  264.  
  265. *-------------------------------------------------------*
  266.             txtlong
  267. *-------------------------------------------------------*
  268.